package client.group;

import java.util.List;

import message.UserToken;

/**
 * Interface describing the operations that must be supported by the client application used to talk with the group server.
 * All methods must be implemented!
 */
public interface GroupInterface
{
	/**
	 * Method used to get a token from the group server.
	 * Right now, there are no security checks.
	 * 
	 * @param username The user whose token is being requested
	 * @return A UserToken describing the permissions of "username."
	 *         If this user does not exist, a null value will be returned.
	 */
	public UserToken getToken(final String username, String password);
	
	/**
	 * Creates a new user.
	 * This method should only succeed if the user invoking it is a member of the special group "ADMIN".
	 * 
	 * @param username The name of the user to create
	 * @param token The token of the user requesting the create operation
	 * @return true if the new user was created, false otherwise
	 */
	public boolean createUser(final String username, final UserToken token, String password);
	
	/**
	 * Deletes a user.
	 * This method should only succeed if the user invoking it is a member of the special group "ADMIN".
	 * Deleting a user should also remove him or her from all existing groups.
	 * 
	 * @param username The name of the user to delete
	 * @param token The token of the user requesting the delete operation
	 * @return true if the user was deleted, false otherwise
	 */
	public boolean deleteUser(final String username, final UserToken token);
	
	/**
	 * Creates a new group.
	 * Any user may create a group, provided that it does not already exist.
	 * 
	 * @param groupname The name of the group to create
	 * @param token The token of the user requesting the create operation
	 * @return true if the new group was created, false otherwise
	 */
	public UserToken createGroup(final String groupname, final UserToken token);
	
	/**
	 * Deletes a group.
	 * This method should only succeed if the user invoking it is the user that originally created the group.
	 * 
	 * @param groupname The name of the group to delete
	 * @param token The token of the user requesting the delete operation
	 * @return true if the group was deleted, false otherwise
	 */
	public UserToken deleteGroup(final String groupname, final UserToken token);
	
	/**
	 * Adds a user to some group.
	 * This method should succeed if the user invoking the operation is the owner of the group.
	 * 
	 * @param user The user to add
	 * @param group The name of the group to which user should be added
	 * @param token The token of the user requesting the create operation
	 * @return true if the user was added, false otherwise
	 */
	public UserToken addUserToGroup(final String user, final String group, final UserToken token);
	
	/**
	 * Removes a user from some group.
	 * This method should succeed if the user invoking the operation is the owner of the group.
	 * 
	 * @param user The name of the user to remove
	 * @param group The name of the group from which user should be removed
	 * @param token The token of the user requesting the remove operation
	 * @return true if the user was removed, false otherwise
	 */
	public UserToken deleteUserFromGroup(final String user, final String group, final UserToken token);
	
	/**
	 * Lists the members of a group.
	 * This method should only succeed if the user invoking the operation is the owner of the specified group.
	 * 
	 * @param group The group whose membership list is requested
	 * @param token The token of the user requesting the list
	 * @return A List of group members. Note that an empty list means
	 *         a group has no members, while a null return indicates
	 *         an error.
	 */
	public List<String> listMembers(final String group, final UserToken token);
	
} // -- end interface GroupClientInterface
